//HDU 4355
#include <bits/stdc++.h>

const double eps=1e-7;

using namespace std;

const int maxn=50005;
typedef long long ll;
template <typename T>
inline T tri(const T &x){return x>=0?x*x*x:-x*x*x;}

double x[maxn],w[maxn];
int n;

inline double f(const double &pos){
    double ans=0;
    for(int i=0;i<n;i++) ans+=w[i]*tri(x[i]-pos);
    return ans;
}

inline int read(){
    int r;char c;bool f=0;
    for(c=getchar();c>'9'||c<'0';c=getchar()) if(c=='-') f=1;
    for(r=0;c<='9'&&c>='0';c=getchar()) r=r*10+c-'0';
    if(f) return -r;
    else return r;
}

int main(){
    int T;
    T=read();
    for(int kase=1;kase<=T;kase++){
        n=read();
        for(int i=0;i<n;i++) scanf("%lf%lf",x+i,w+i);
        double l=x[0],r=x[n-1];
        while(r-l>eps){
            //printf("l=%.2f,r=%.2f\n",l,r);
            double x1,x2,y1,y2;
            x1=(2*l+r)/3;
            x2=(l+2*r)/3;
            //printf("x1=%.2f,x2=%.2f\n",x1,x2);
            y1=f(x1);y2=f(x2);
            if(y1>y2) l=x1;
            else r=x2;
        }
        printf("Case #%d: %.0f\n",kase,f(l));
        //printf("l=%.1f\n",l);
    }
}
